﻿Ext.namespace('EHSubmit.MessageBox.CheckDetails');


    //---------------处理回复------------------------
    function reply(){
    //---------------原来的---------------------------
    //    var messageBox = Ext.getCmp('messageBox');
    //    var checkDetailsForm = Ext.getCmp('checkDetailsForm'); 
    //    messageBox.remove(checkDetailsForm);          //, true);   不销毁
    //    messageBox.add(EHSubmit.MessageBox.WriteMsg.Form);  
    //    var to = Ext.getCmp('to');
    //    var title = Ext.getCmp('title');
    //    to.value = '发来信息的邮箱';  //具体还得实时处理
    //    title.value = '发来的信息的主题';
    //    messageBox.doLayout();  //refresh the layout
        
        var detailsWin = Ext.getCmp('msgDetailsWindow');
        detailsWin.close();
           
        //----------只允许有一个写消息窗----------
        EHSubmit.showWin(EHSubmit.MessageBox.WriteMsg.window);
    };

    EHSubmit.MessageBox.CheckDetails.removeMsg = function removeMsg() {
        var thisGridID = EHSubmit.MessageBox.gridID;
        var msgID = EHSubmit.MessageBox.msgData.ID;
        var msgIDJson = '[' + msgID + ']';
        Ext.Ajax.request({
            url: EHSubmit.ajaxRoot + 'MessageHandler.ashx',
            success: function(response, opts) {
                var result = Ext.decode(response.responseText).msg;
                Ext.MessageBox.alert("提示", result);
                //-------删除成功后，要刷新一下grid----------
                Ext.getCmp(thisGridID).store.reload();
            },
            failure: function(response, opts) {
                var result = Ext.decode(response.responseText).msg;
                Ext.MessageBox.alert('错误', result);
            },
            params: { Op: 'msgRemove', gridID: thisGridID, msgID: msgIDJson }
        });
        //---关闭当前窗口------------
        var msgDetailsWindow = Ext.getCmp('msgDetailsWindow');
        msgDetailsWindow.close();
    }

    //----------------查看信息主窗口的信息内容-------------
    EHSubmit.MessageBox.CheckDetails.content = {
        layout: 'fit',
        id: 'msgContext',
        xtype: 'panel',
        //readOnly: true,   //read-only
        frame: false,
        border: false,
        html:''
    };

//-------------查看信息主窗口----------
//EHSubmit.MessageBox.CheckDetails.innerForm = {
//    xtype: 'form',
//    id: 'checkMsgForm',
//    border:true,
//    bodyStyle: 'margins:5px 5px 5px 5px;',
//    monitorValid: true,


//    //-------中间部分----------
//    items: [EHSubmit.MessageBox.CheckDetails.content],

//};


//-------包含查看信息窗口的容器--------------
//EHSubmit.MessageBox.CheckDetails.Form = {
//    id: 'checkDetailsForm',
//    layout: 'form',
//    bodyStyle: 'padding:15px;',
//    border: false,
//    items: [EHSubmit.MessageBox.CheckDetails.innerForm]
//};

    EHSubmit.MessageBox.CheckDetails.window = {
        id: 'msgDetailsWindow',
        xtype: 'window',
        width: 700,
        height: 450,
        plain: true,
        border: true,
        layout: 'fit',
        modal: true,
        title: '查看信息',
        frame: true,

        //-------tooltopbar-------                    //考虑要不要加上上下页之间的跳转
        tbar: [{
            text: '',
            tooltip: '',
            iconCls: 'add',
            ref: '../topReplyButton',
            handler: reply
        }, '-', {
            text: '删除',
            tooltip: '删除',
            iconCls: 'remove',
            handler: EHSubmit.MessageBox.CheckDetails.removeMsg
        }, '-', {
            text: '关闭',
            tooltip: '关闭',
            iconCls: 'close',
            handler: function() {
                //----关闭当前窗口---------
                var detailsWin = Ext.getCmp('msgDetailsWindow');
                detailsWin.close();
            }
        }],

        items: [EHSubmit.MessageBox.CheckDetails.content],

            //-------footbar--------------
        fbar: [{
            text: '',
            tooltip: '',
            iconCls: 'add',
            ref: '../footReplyButton',
            handler: reply
        }, '-', {
            text: '删除',
            tooltip: '删除',
            iconCls: 'remove',
            handler: EHSubmit.MessageBox.CheckDetails.removeMsg
        }, '-', {
            text: '关闭',
            tooltip: '关闭',
            iconCls: 'close',
            handler: function() {
                //----关闭当前窗口---------
                var detailsWin = Ext.getCmp('msgDetailsWindow');
                detailsWin.close();
            }
        }],
        listeners:{
            activate:function(thisWin){
                var topReplyButton = thisWin.topReplyButton;
                var footReplyButton = thisWin.footReplyButton;
                var msg = thisWin.get('msgContext');
                
                //-----变量用作判断消息来着收件箱还是发件箱---------------
                var isInbox = EHSubmit.MessageBox.isInbox;
                
                var msgData = EHSubmit.MessageBox.msgData;
                //var r = EHSubmit.MessageBox.CheckRecords.record;               
                var topTemplate =null;
                if(isInbox){      //说明消息来自收件箱
                    //-----刷新按钮外观-------------
                    topReplyButton.setText('回复');
                    topReplyButton.setTooltip('回复'); 
                    footReplyButton.setText('回复');
                    footReplyButton.setTooltip('回复'); 
                    
                    //-----刷新panel----------------
                    topTemplate = new Ext.Template([
                       '<div>',
                           '<b>标题</b>:&nbsp;{Title}<br/>',
                           '<b>发件人</b>:&nbsp;{SenderName}<br />',
                           '<b>时间</b>:&nbsp;{RecvTime}<br />',
                           '<b>收件人</b>:&nbsp;{ReceiverName}<br />',
                           '<hr/>',
                           '<p>{Content}</p>',
                       '</div>'
                    ]);
                }
                else{             //说明消息来自发件箱
                    //-----刷新按钮外观-------------
                    topReplyButton.setText('再次发送');
                    topReplyButton.setTooltip('再次发送'); 
                    footReplyButton.setText('再次发送');
                    footReplyButton.setTooltip('再次发送'); 

                    
                    //-----刷新panel----------------
                    topTemplate = new Ext.Template([
                       '<div>',
                           '<b>标题</b>:&nbsp;{Title}<br/>',
                           '<b>发件人</b>:&nbsp;{SenderName}<br />',
                           '<b>时间</b>:&nbsp;{SendTime}<br />',
                           '<b>收件人</b>:&nbsp;{ReceiverName}<br />',
                           '<hr/>',
                           '<p>{Content}</p>',
                       '</div>'
                    ]);

                }
                topTemplate.overwrite(msg.body, msgData);
                
            }
        }
    };